package com.rudisoft.analysis;

import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class Parser {

	public Parser(String string) {
		try {
			File dir = new File(string);
			if (dir.isDirectory()) {
				parseDir(dir);
			} else {
				throw new IOException("[" + string + "] is not a directoy");
			}

		} catch (Exception e) {
			System.err.println("error in Parser: " + e.toString());
		}

	}

	private void parseDir(File dir) {
		try {
			File[] list = dir.listFiles(new FileFilter() {
				public boolean accept(File file) {
					return (file.isDirectory() || file.getName().endsWith(
							".java"));
				}
			});
			for(int i=0; i<list.length; i++){
				if(list[i].isDirectory()){
					parseDir(dir);
				} else {
					parseFile(list[i]);
				}
			}

		} catch (Exception e) {
			System.err.println("error in parseDir: " + e.toString());
		}
	}

	private void parseFile(File file) {
		try {
			FileInputStream fis = new FileInputStream(file);
			InputStreamReader isr = new InputStreamReader(fis);
			LineNumberReader lr = new LineNumberReader(isr);
			
			
			
			
			fis.close();

		} catch (Exception e) {
			System.err.println("error in parseFile: " + e.toString());
		}
		
	}

	public static void main(String args[]) {
		if (args.length == 1) {
			new Parser(args[0]);
		} else {
			System.err.println("please provide directory");
		}
	}

}
